package com.base.cn.platform.os.controller.mobile.teacher;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.manage.teacher.SysTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Map;

/**
 * H5端 讲师Controller
 * @author LIZHIPENG
 * @create 2018-06-08 上午 10:34
 */
@Controller
@RequestMapping("/mobile/teacher")
public class MobileTeacherController extends MobileBaseController {

    @Autowired
    private SysTeacherService sysTeacherService;

    /**
     * 初始化讲师列表页面
     * @return String
     */
    @RequestMapping("/teacherList")
    public String teacherList(){
        return resultPage("/teacher/teacher-list");
    }

    /**
     * 查询讲师列表
     * @param model Model
     * @param currentPage 页码
     * @param params 查询条件
     * @return String
     */
    @RequestMapping("/ajaxTeacherList")
    public String ajaxTeacherList(Model model,
                                  @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                  @RequestBody Map<String, Object> params){
        params.put("teacherIdentity","1"); //查询讲师
        Map<String, Object> dataMap = sysTeacherService.findWebTeacherListPage(params, currentPage, 8, false, false, false);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/teacher/ajax-teacher-list");
    }

    /**
     * 查看讲师详情
     * @param teacherId 讲师ID
     * @return String
     */
    @RequestMapping("/teacherInfo")
    public String teacherInfo(Model model,
                              @RequestParam("teacherId")BigDecimal teacherId,@RequestParam(value = "catalogId", required = false, defaultValue = "0") BigDecimal catalogId,@RequestParam(value = "packageCourseId", required = false, defaultValue = "0") BigDecimal packageCourseId,@RequestParam(value = "courseId", required = false, defaultValue = "0") BigDecimal courseId,@RequestParam(value =  "isCourse",required = false,defaultValue = "false") boolean isCourse){
        Map<String, Object> teacher = sysTeacherService.findSysTeacherById(teacherId, false, false, false, false, false);

        model.addAttribute("isCourse", isCourse);
        model.addAttribute("teacher", teacher);
        model.addAttribute("catalogId", catalogId);
        model.addAttribute("packageCourseId", packageCourseId);
        model.addAttribute("courseId", courseId);
        return resultPage("/teacher/teacher-info");
    }
}
